﻿using Coldairarrow.Business.DataView;
using Coldairarrow.Entity.DataView;
using Coldairarrow.IBusiness;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.DataView
{
    [Route("/DataView/[controller]/[action]")]
    public class blade_visual_dbController : BaseApiController
    {
        #region DI
        readonly IOperator _operator;
        public blade_visual_dbController(Iblade_visual_dbBusiness blade_visual_dbBus, IOperator @operator)
        {
            _blade_visual_dbBus = blade_visual_dbBus;
            _operator = @operator;
        }

        Iblade_visual_dbBusiness _blade_visual_dbBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<blade_visual_db>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _blade_visual_dbBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<blade_visual_db> GetTheData(IdInputDTO input)
        {
            return await _blade_visual_dbBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(blade_visual_db data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                //data.create_user = _operator.UserId;
                //data.create_dept = _operator?.Property.DepartmentId;
                data.create_time = DateTime.Now;
                data.is_deleted = 0;

                await _blade_visual_dbBus.AddDataAsync(data);
            }
            else
            {
                //data.update_user = _operator.UserId;
                data.update_time = DateTime.Now;
                await _blade_visual_dbBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _blade_visual_dbBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}